﻿////////////////////////////////////////////////////////////////
///
/// File: BodyContent.cs
/// Author: Lucio Davide Spano
/// Last update: 27 July 2012
/// Description: Delegate that defines the behaviour of a ground 
///              term for the Kinect platform
/// To do: 
/// ------------------------------------------------------------
/// Copyright (c) 2012 Lucio Davide Spano 
///                     (lucio.davide.spano@isti.cnr.it)
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------
////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;


using GestIT;

namespace BodyGestIT
{
    public class BodyContent : ExpContent
    {
        public AcceptsDecorator AcceptsDecorator { get; set; }

        public BodyFeature Feature { get; set; }

        public BodyContent()
            : base()
        {
            this.AcceptsDecorator = new AcceptsDecorator(AlwaysAccept);
        }

        public BodyContent(AcceptsDecorator decorator)
            : this()
        {
            this.AcceptsDecorator = decorator;
        }

        public override bool Accepts(ExpEventArgs args, Token token)
        {
            if (!(args is BodyEventArgs) || 
                !(token is BodyToken) )
            {
                return false;
            }
            BodyEventArgs bargs = (BodyEventArgs)args;
            BodyToken btoken = (BodyToken)token;
            if(!bargs.Skeleton.JointChanged[(int) Feature])
            {
                return false;
            }
            return AcceptsDecorator(bargs, btoken);
        }

        public override bool Consume(ExpEventArgs args, Token token)
        {
            if (!(args is BodyEventArgs) || !(token is BodyToken))
            {
                return false;
            }
            BodyEventArgs bargs = (BodyEventArgs)args;
            BodyToken btoken = (BodyToken)token;

            btoken.Save(bargs.Skeleton);
            return true;
        }

        private bool AlwaysAccept(BodyEventArgs args, BodyToken token)
        {
            return true;
        }
    }

    public enum BodyFeature
    {
        HipCenter = 0,
        Spine = 1,
        ShoulderCenter = 2,
        Head = 3,
        ShoulderLeft = 4,
        ElbowLeft = 5,
        WristLeft = 6,
        HandLeft = 7,
        ShoulderRight = 8,
        ElbowRight = 9,
        WristRight = 10,
        HandRight = 11,
        HipLeft = 12,
        KneeLeft = 13,
        AnkleLeft = 14,
        FootLeft = 15,
        HipRight = 16,
        KneeRight = 17,
        AnkleRight = 18,
        FootRight = 19,
        OpenRightHand = 20,
        OpenLeftHand = 21

    }

    public delegate bool AcceptsDecorator(BodyEventArgs args, BodyToken token);
    
}
